package com.younion.action.consumer.impl;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.younion.action.consumer.AbstractRequestConsumer;
import com.younion.action.interactive.mobile.ApiConstant;
import com.younion.action.interactive.mobile.ResultObject;
import com.younion.business.ICardEntityService;
import com.younion.model.CustomerDetailedResult;
import com.younion.util.HttpRequestUtils;
import com.younion.util.JsonUtils;
import com.younion.vo.API_CardEntityVO;

public class CustomerDetailGetConsumer extends AbstractRequestConsumer {
	private ICardEntityService cardEntityService;

	@Override
	public String execute(HttpServletRequest request,
			HttpServletResponse response) throws Exception {
		return getCardDetail(request, response);
	}

	public String getCardDetail(HttpServletRequest request,
			HttpServletResponse response) {
		String card_id = request.getParameter("card_id");
		CustomerDetailedResult customerDetailedResult = new CustomerDetailedResult();

		ResultObject resultObject = new ResultObject();
		try {
			Map paramMap = new HashMap();
			paramMap.put("id", card_id);
			List<API_CardEntityVO> api_CardEntityVOList = null;
			api_CardEntityVOList = cardEntityService
					.selectCustomerByCard(paramMap);
			if (api_CardEntityVOList != null && api_CardEntityVOList.size() > 0) {
				API_CardEntityVO api_CardEntityVO = api_CardEntityVOList.get(0);
				customerDetailedResult.setCard_id(card_id);
				customerDetailedResult.setCustomer_introduce(api_CardEntityVO
						.getCustomerVO().getIntroduce());
				customerDetailedResult.setShops(api_CardEntityVO
						.getCustomerVO().getShops());
			}
			resultObject.setResult(customerDetailedResult);
			resultObject.setStatus(ApiConstant.SUCCESS_STATUS);

		} catch (Exception e) {
			resultObject.setStatus(ApiConstant.FALSE_STATUS);
			resultObject.setMsg(ApiConstant.PUBLIC_EXCEPTION);
			e.printStackTrace();
		}

		HttpRequestUtils.printContent(JsonUtils.parseObj2Json(resultObject),
				response);
		return null;
	}

	public void setCardEntityService(ICardEntityService cardEntityService) {
		this.cardEntityService = cardEntityService;
	}
}
